<template>
    <div class="caroffer-insure">
        <x-header v-show="!isWeChar">
            <div slot="default" class="common__header--title">报价</div>
            <div @click="goBack" slot="overwrite-left"><img slot="icon" src="~assets/x3/ico/goback1.png" class="go-back"></div>
        </x-header>
        <car-header></car-header>
        <div class="car-content">
            <group class="car__formPolicy--group">
                <cell class="car-insure-list">
                    <span class="car__list--title" slot="after-title">
                        <img slot="icon" src="~assets/car/car-date.png" class="go-back car-list-img">
                        <span style="color: #fff;" class="car__iconspan--title">保险起期</span>
                    </span>
                </cell>
                <div class="car__formPolicy">
                    <div>
                        <cell class="caroffer-swich">
                            <div slot="inline-desc" class="car__input">交强险</div>
                            <div slot="default"><input v-model="strongInsure" type="checkbox" class="weui-switch"></div>
                        </cell>
                        <datetime :start-date="startDate" v-show="strongInsure" placeholder="" v-model="tprpTmainDto.mtplStartDate" @on-change="mtplStartDateChange(1)" confirm-text="完成" cancel-text="取消">
                            <div class="car__input" slot="title">
                                交强险起期
                            </div>
                        </datetime>
                        <cell class="caroffer-swich">
                            <div slot="inline-desc" class="car__input">商业险</div>
                            <div slot="default"><input v-model="commInsure" type="checkbox" class="weui-switch"></div>
                        </cell>

                        <datetime :start-date="startDate" v-show="commInsure" placeholder="" v-model="tprpTmainDto.startDate" @on-change="mtplStartDateChange(2)" confirm-text="完成" cancel-text="取消">
                            <div class="car__input" slot="title">
                                商业险起期
                            </div>
                        </datetime>
                    </div>
                </div>
            </group>
            <group>

                <cell class="car-insure-list">
                    <span class="car__list--title" slot="after-title">
                        <img slot="icon" src="~assets/car/pack.png" class="go-back car-list-img">
                        <span style="color: #fff;" class="car__iconspan--title">套餐</span>
                    </span>
                </cell>

                <tab v-model="packIndex" v-show="commInsure">
                    <tab-item>自定义</tab-item>
                    <tab-item v-for="(item,index) in car.packNameList" :key="index">{{item}}</tab-item>
                </tab>
            </group>

            <group class="car__formPolicy--group">
                <cell class="car-insure-list">
                    <span class="car__list--title" slot="after-title">
                        <img slot="icon" src="~assets/car/baseinsure.png" class="go-back car-list-img">
                        <span style="color: #fff;" class="car__iconspan--title">基本险</span>
                    </span>
                </cell>
                <div v-show="commInsure" class="car__formPolicy">
                    <div>
                        <cell v-for="(mainRisk,index) in car.mainRiskSave" v-show="mainRisk.kindCode!='BZ'" :key="index" class="caroffer-swich">
                            <div slot="inline-desc" class="caroffrt-input">{{car.saveKind[mainRisk.kindCode].kindCName}}</div>
                            <div slot="default">
                                <selector v-show="car.seleRateSave[mainRisk.kindCode].isSetData" class="carinfo-selector sele-caroffer" ref="defaultValueRef" :options="car.seleRateSave[mainRisk.kindCode].seleData" v-model="seleValue[mainRisk.kindCode].defValue"></selector>
                                <check-icon @click.native="valNonDeductible(mainRisk.kindCode)" v-show="mainRisk.nonDeductibleKindCode!=null&&mainRisk.nonDeductibleKindCode!=''" class="insure__input offer-min-input" slot="right" :value.sync="seleValue[mainRisk.kindCode].nonSele">不计免赔&nbsp</check-icon>

                                <div v-show="mainRisk.nonDeductibleKindCode==null||mainRisk.nonDeductibleKindCode==''" class="vux-check-icon insure__input offer-min-input" slot="right" style="width:  100px;"></div>

                                <input v-model="seleValue[mainRisk.kindCode].mainSele" @change="mainChange(mainRisk.kindCode)" type="checkbox" class="weui-switch"></div>
                        </cell>
                        <!-- <cell v-for="(mainRisk,index) in car.mainRiskSave" v-show="mainRisk.kindCode!='BZ'" :key="index" class="caroffer-swich">
                            <div slot="title" class="carrisk-name">
                                <check-icon @click.native="mainChange(mainRisk.kindCode)" class="insure__input" slot="right" :value.sync="seleValue[mainRisk.kindCode].mainSele">{{car.saveKind[mainRisk.kindCode].kindCName}}</check-icon>
                            </div>

                            <div slot="default" class="base-car-selector">

                                <check-icon v-show="mainRisk.nonDeductibleKindCode!=null&&mainRisk.nonDeductibleKindCode!=''" class="insure__input offer-min-input" slot="right" :value.sync="seleValue[mainRisk.kindCode].nonSele">不计免赔&nbsp</check-icon>

                                <selector v-show="car.seleRateSave[mainRisk.kindCode].isSetData" class="carinfo-selector sele-caroffer" ref="defaultValueRef" :options="car.seleRateSave[mainRisk.kindCode].seleData" v-model="seleValue[mainRisk.kindCode].defValue"></selector>

                                <div v-show="!car.seleRateSave[mainRisk.kindCode].isSetData" class="sele-caroffer"></div>

                            </div>
                        </cell> -->
                    </div>
                </div>
            </group>

            <group class="car__formPolicy--group">
                <cell class="car-insure-list">
                    <span class="car__list--title" slot="after-title">
                        <img slot="icon" src="~assets/car/add.png" class="go-back car-list-img">
                        <span style="color: #fff;" class="car__iconspan--title">附加险</span>
                    </span>
                </cell>
                <div v-show="commInsure" class="car__formPolicy">
                    <div>
                        <cell v-for="(mainRisk,index) in car.additionalInsurance" :key="index" class="caroffer-swich">
                            <div slot="inline-desc" class="caroffrt-input">{{car.saveKind[mainRisk.kindCode].kindCName}}</div>
                            <div slot="default">
                                <selector v-show="car.seleRateSave[mainRisk.kindCode].isSetData" class="carinfo-selector sele-caroffer" ref="defaultValueRef" :options="car.seleRateSave[mainRisk.kindCode].seleData" v-model="seleValue[mainRisk.kindCode].defValue"></selector>
                                <check-icon @click.native="valNonDeductible(mainRisk.kindCode)" v-show="mainRisk.nonDeductibleKindCode!=null&&mainRisk.nonDeductibleKindCode!=''" class="insure__input offer-min-input" slot="right" :value.sync="seleValue[mainRisk.kindCode].nonSele">不计免赔&nbsp</check-icon>

                                <div v-show="mainRisk.nonDeductibleKindCode==null||mainRisk.nonDeductibleKindCode==''" class="vux-check-icon insure__input offer-min-input" slot="right" style="width:  100px;"></div>

                                <input v-model="seleValue[mainRisk.kindCode].mainSele" @change="addChange(mainRisk.kindCode)" type="checkbox" class="weui-switch"></div>
                        </cell>
                        <!-- <cell v-for="(mainRisk,index) in car.additionalInsurance" v-show="mainRisk.kindCode!='BZ'" :key="index" class="caroffer-swich">
                            <div slot="title" class="carrisk-name">
                                <check-icon @click.native="mainChange(mainRisk.kindCode)" class="insure__input" slot="right" :value.sync="seleValue[mainRisk.kindCode].mainSele">{{car.saveKind[mainRisk.kindCode].kindCName}}</check-icon>
                            </div>

                            <div slot="default" class="base-car-selector">

                                <check-icon v-show="mainRisk.nonDeductibleKindCode!=null&&mainRisk.nonDeductibleKindCode!=''" class="insure__input offer-min-input" slot="right" :value.sync="seleValue[mainRisk.kindCode].nonSele">不计免赔&nbsp</check-icon>

                                <selector v-show="car.seleRateSave[mainRisk.kindCode].isSetData" class="carinfo-selector sele-caroffer" ref="defaultValueRef" :options="car.seleRateSave[mainRisk.kindCode].seleData" v-model="seleValue[mainRisk.kindCode].defValue"></selector>

                                <div v-show="!car.seleRateSave[mainRisk.kindCode].isSetData" class="sele-caroffer"></div>

                            </div>
                        </cell> -->
                    </div>
                </div>
            </group>

            <group v-show="seleCrossList.length!=0&&(car.seleAxtxList.length!=0||car.seleAtqqbList.length!=0)&&(strongInsure||commInsure)" class="car-shadow">
                <cell>
                    <span class="car__list--title" slot="after-title">
                        <img slot="icon" src="~assets/car/accident_blue.png" class="go-back car-list-img">
                        <span class="car__iconspan--title">意外险</span>
                    </span>
                    <div slot="default">
                        <selector class="carinfo-selector title-selector" ref="defaultValueRef" title="被保险人：" :options="seleCrossList" v-model="seleCrossValue"></selector>
                    </div>
                </cell>

                <div class="car__formPolicy">
                    <div>
                        <cell v-show="car.seleAxtxList.length!=0" class="caroffer-swich">
                            <div slot="inline-desc" class="caroffrt-input">安行天下</div>
                            <div slot="default">
                                <selector class="sele-caroffer accident" ref="defaultValueRef" :options="car.seleAxtxList" v-model="seleAxtx"></selector>
                                <input v-model="axtxInsure" type="checkbox" class="weui-switch"></div>
                        </cell>
                        <cell v-show="car.seleAtqqbList.length!=0" class="caroffer-swich">
                            <div slot="inline-desc" class="caroffrt-input">安途全球宝</div>
                            <div slot="default">
                                <selector class="sele-caroffer accident" ref="defaultValueRef" :options="car.seleAtqqbList" v-model="seleAtqqb"></selector>
                                <input v-model="atqqbInsure" type="checkbox" class="weui-switch"></div>
                        </cell>

                        <cell v-show="axtxInsure" class="item-offer-color" is-link :border-intent="false" :arrow-direction="axtxDetail ? 'up' : 'down'" @click.native="axtxDetail = !axtxDetail">
                            <div slot="inline-desc" class="car-offer-font-fff">安行天下</div>
                            <div slot="default" class="car-offer-font-fff">总保额 : ¥ {{seleAxtx.sumAmount|price}}&nbsp</div>
                        </cell>
                        <template v-if="axtxDetail">

                            <div class="car-offResult car-back">
                                <cell>
                                    <div slot="after-title" class="item-text-car car-offer-font-000">险别</div>
                                    <div slot="default" class="car-offer-font-blue car-offer-font-000" style="font-size:13px">保额( ¥ )</div>
                                </cell>

                                <cell v-for="(item,index) in seleAxtx.kinds" :key="index">
                                    <div slot="after-title" class="item-text-car">{{item.cvgName}}</div>
                                    <div slot="default" class="car-offer-font-blue" style="font-size:13px">保额:{{item.adultStr|price}}</div>
                                </cell>
                            </div>

                        </template>

                        <cell v-show="atqqbInsure" class="item-offer-color" is-link :border-intent="false" :arrow-direction="atqqbDetail ? 'up' : 'down'" @click.native="atqqbDetail = !atqqbDetail">
                            <div slot="inline-desc" class="car-offer-font-fff">安途全球宝</div>
                            <div slot="default" class="car-offer-font-fff">总保额 : ¥ {{seleAtqqb.sumAmount|price}}&nbsp</div>
                        </cell>
                        <template v-if="atqqbDetail">

                            <div class="car-offResult car-back">
                                <cell>
                                    <div slot="after-title" class="item-text-car car-offer-font-000">险别</div>
                                    <div slot="default" class="car-offer-font-blue car-offer-font-000" style="font-size:13px">保额( ¥ )</div>
                                </cell>

                                <cell v-for="(item,index) in seleAtqqb.kinds" :key="index">
                                    <div slot="after-title" class="item-text-car">{{item.cvgName}}</div>
                                    <div slot="default" class="car-offer-font-blue" style="font-size:13px">保额:{{item.adultStr|price}}</div>
                                </cell>
                            </div>

                        </template>

                    </div>
                </div>
            </group>
        </div>

        <div v-transfer-dom>
            <x-dialog v-model="showVal" class="dialog-demo">
                <div style="padding:5px;">
                    <group class="SendEmail__formPolicy--group">
                        <cell class="SendEmail__Einv--title">
                            <span class="SendEmail__list--title" slot="after-title">
                                <span class="SendEmail__iconspan"></span>
                                <span class="SendEmail__iconspan--title">转保校验&nbsp</span>
                            </span>
                        </cell>
                        <div class="SendEmail__formPolicy">
                            <x-input v-model="answer" placeholder="验证码">
                                <img slot="right-full-height" :src="car.verifyRes.renewalQuestion">
                                <!-- <div class="common__input " slot="label">
                                    <img src="~assets/x3/ico/icon-email.png" class="icon-img">&nbsp&nbsp
                                </div> -->
                            </x-input>
                        </div>
                    </group>
                    <div v-show="haveError" class="common_errorMsg">
                        <badge text="!"></badge>
                        <span>{{errorMessage}}</span>
                    </div>
                    <div class="dialog-btnlist">
                        <x-button @click.native="carVail()" :style="queryStyle" type="primary" mini>提交</x-button>
                        <x-button @click.native="showVal=false;" mini>取消</x-button>
                    </div>
                </div>
            </x-dialog>
        </div>

        <div style="height: 80px;"></div>
        <!-- <div @click="offer" class="insure__footer">
            <div :style="queryStyle">{{text}}</div>
        </div> -->

        <div class="car_footer">
            <div class="car_leftbtn">
                <div class="details-alert">
                    <img slot="icon" style="width: 15px;" src="~assets/x3/ico/smal-1.png">&nbsp提示:&nbsp套餐搭配更加合理
                </div>
                <!-- <span>999</span> -->
            </div>
            <div @click="goOffer()" :style="queryStyle" class="car_rightbtn">{{text}}</div>
        </div>

        <!-- <sele-country></sele-country> -->
        <!-- 投保声明  理赔须知 -->

    </div>
</template>

<script>
import carHeader from "src/components/car/carHeader";
import { RequestUrl } from "src/common/url";
// import Config from "src/common/config/insureConfig";
// import CarConfig from "src/common/config/carConfig";
import {
    Car_Mutations,
    RouteUrl,
    Mutations
} from "src/common/const";
import {
    XHeader,
    Group,
    Cell,
    XInput,
    Datetime,
    XSwitch,
    Selector,
    XButton,
    XDialog,
    CellFormPreview,
    Actionsheet,
    Toast,
    CheckIcon,
    GroupTitle,
    Tab, TabItem,
    TransferDomDirective as TransferDom,
    Badge
} from "vux";
import Validation from "src/common/util/validation";
import DateUtil from "src/common/util/dateUtil";
import { mapState, mapActions } from "vuex";
import { setTimeout } from 'timers';
export default {
    directives: {
        TransferDom
    },
    components: {
        CellFormPreview,
        XDialog,
        Selector,
        XHeader,
        Group,
        Cell,
        XInput,
        Datetime,
        XSwitch,
        XButton,
        Actionsheet,
        Toast,
        CheckIcon,
        GroupTitle,
        carHeader,
        Tab, TabItem,
        Badge
    },
    computed: mapState({
        // insure: "insure",
        isLoading: "isLoading",
        user: "user",

        saveInsure: "saveInsure",
        detailsStore: "detailsStore",
        isWeChar: "isWeChar",
        carAddr: "carAddr",
        shareData: "shareData",
        initIndexData: "initIndexData",
        car: "car",
        queryStyle: "queryStyle",
        baseIsQuery: "baseIsQuery"
    }),
    data() {
        return {
            haveError: false,
            answer: "",
            errorMessage: "",
            showVal: false,
            packIndex: 0,
            startDate: DateUtil.getDateTomorrow(1),
            tprpTmainDto: {
                combineFlag: "",
                proposalNo: "",
                mtplProposalNo: "",
                autonomyAdjustValue: "",
                channelAdjustValue: "",
                salerNumber: "",
                salerName: "",
                trdSalesCode: "",
                startDate: DateUtil.getDateTomorrow(1),
                startHour: "0",
                endDate: "",
                endHour: "24",
                mtplStartDate: DateUtil.getDateTomorrow(1),
                mtplStartHour: "0",
                mtplEndDate: "",
                mtplEndHour: "24"
            },
            seleValue: {},
            fuelTypeList: [],
            type: "car",
            useNatureList: [],
            // carKindList: [],
            seleCarKind: "A0",
            hourseType: [], //房屋类型
            datatime: DateUtil.getNowDateStr_Ymd(),
            buildStructure: "",
            strongInsure: true,
            commInsure: true,
            fuelType: "",
            text: "保费计算",
            packSave: {},
            isBaseSave: false,
            seleCrossList: [],
            seleCrossValue: 1,
            seleAxtx: {},
            seleAtqqb: {},
            axtxInsure: false,
            atqqbInsure: false,
            axtxDetail: false,
            atqqbDetail: false,
            renewalDataChange: {
                renewalStartDate: "",
                renewalMtplStartDate: "",
                isChangeData: false,
                isChangeMtplData: false,
                renewalFlag: "0"
            }
        };
    },
    watch: {
        axtxInsure(cur, old) {
            if (cur && typeof (this.seleAxtx.planCode) == "undefined") {
                this.axtxInsure = false;
                this.$common.showErrorMsg(this, "请选择购买价格!");
            }
        },
        atqqbInsure(cur, old) {
            if (cur && typeof (this.seleAtqqb.planCode) == "undefined") {
                this.atqqbInsure = false;
                this.$common.showErrorMsg(this, "请选择购买价格!");
            }
        },
        seleCrossValue(cur, old) {
            let query = {
                _this: this,
                insureType: cur,
                type: "query"
            }
            this.$common.storeCommit(this, Car_Mutations.CROSS_SALE_PLAN, query);
        },
        strongInsure(cur, old) {
            // if (cur && this.tprpTmainDto.mtplStartDate) {
            //     this.tprpTmainDto.mtplStartDate = DateUtil.getDateTomorrow(1);
            // }
        },
        baseIsQuery(cur, old) {
            this.setText(cur);
        },
        packIndex(cur, old) {
            if (old == 0) {
                this.isBaseSave = true;
            } else {
                this.isBaseSave = false;
            }
            if (cur != 0) {
                let name = this.car.packNameList[cur - 1];
                this.setPack(name);
            } else {
                this.setPack(1);
            }
        }
    },
    filters: {
        price(val) {
            if (val != "" && val != null) {
                if (val.indexOf("元") > -1 || val.indexOf("天") > -1) {
                    return val;
                }

                if (val.indexOf("*") > -1) {
                    let priList = val.split("*");
                    let num = priList[0];
                    let stPrice = priList[1] + "";
                    stPrice = stPrice.split(",").join("");
                    let price = parseFloat(stPrice) / 10000;
                    return num + "*" + price + "万";
                } else {
                    val = val.split(",").join("");
                    let price = parseFloat(val) / 10000;
                    return price + "万";
                }
            } else {
                return val;
            }
        }
    },
    methods: {
        mtplStartDateChange(type) {
            let mtplData = this.tprpTmainDto.mtplStartDate + "";
            let data = this.tprpTmainDto.startDate + "";
            if (this.renewalDataChange.renewalFlag == "1") {
                if (this.renewalDataChange.renewalMtplStartDate != "" && this.renewalDataChange.renewalMtplStartDate != mtplData && type == 1) {
                    if (DateUtil.getComStData(mtplData, this.renewalDataChange.renewalMtplStartDate)) {
                        this.$common.showErrorMsg(this, "续保车辆交强险投保日期大于续保日期会导致脱保!");
                    } else if (!DateUtil.getComStData(mtplData, this.renewalDataChange.renewalMtplStartDate)) {
                        this.$common.showErrorMsg(this, "续保车辆交强险投保日期小于续保日期会导致重复投保!");
                    }
                }
                if (this.renewalDataChange.renewalStartDate != "" && data != this.renewalDataChange.renewalStartDate && type == 2) {
                    if (DateUtil.getComStData(data, this.renewalDataChange.renewalStartDate)) {
                        this.$common.showErrorMsg(this, "续保车辆商业险投保日期大于续保日期会导致脱保!");
                    } else if (!DateUtil.getComStData(data, this.renewalDataChange.renewalStartDate)) {
                        this.$common.showErrorMsg(this, "续保车辆商业险投保日期大于续保日期会导致重复投保!");
                    }
                }
            }
        },
        carVail() {
            if (this.answer == "") {
                this.haveError = true;
                this.errorMessage = "验证码不能为空!";
            } else {
                if (this.baseIsQuery) {
                    let query = {
                        _this: this,
                        answer: this.answer
                    }
                    this.$common.storeCommit(this, Car_Mutations.VERIFY, query);
                }
            }
        },
        valNonDeductible(val) {
            if (this.seleValue[val].nonSele && !this.seleValue[val].mainSele) {
                this.seleValue[val].mainSele = true;
            }
        },
        showErrorMsg(errorMsg) {
            this.$vux.alert.show({ content: this.$common.alertMsg(errorMsg, "red;") });
            return false;
        },
        setPack(packName) {
            if (packName != 1) {
                if (this.isBaseSave) {
                    this.packSave['自定义'] = {};
                    this.packSave['自定义'] = this.$common.getNewObject(this.seleValue);
                }
                if (typeof (this.packSave[packName]) == "undefined") {
                    let pack = this.car.packList[packName];
                    //设置主险套餐
                    this.setKindPack(this.car.mainRiskSave, pack);
                    //设置附加险种套餐
                    this.setKindPack(this.car.additionalInsurance, pack);
                    this.packSave[packName] = this.$common.getNewObject(this.seleValue);
                } else {
                    this.seleValue = this.packSave[packName];
                }

            } else {
                this.seleValue = this.packSave['自定义'];
            }

            // for (let index in this.car.mainRiskSave) {
            //     let mainItem = this.car.mainRiskSave[index];

            // }
            // console.log(this.car.mainRiskSave);
            // console.log(this.car.additionalInsurance);
            // console.log(this.seleValue);
        },
        setKindPack(kindList, pack) {
            // debugger
            for (let index in this.car.mainRiskSave) {
                let mainKind = kindList[index];
                //主险选择

                if (typeof (pack[mainKind.kindCode]) != "undefined") {
                    this.seleValue[mainKind.kindCode].mainSele = true;
                    //设置选项值
                    let defPack = pack[mainKind.kindCode].forehead;
                    if (defPack != null && defPack != "") {
                        this.seleValue[mainKind.kindCode].defValue = defPack;
                    }
                } else {
                    this.seleValue[mainKind.kindCode].mainSele = false;
                }
                if (mainKind.nonDeductibleKindCode != null && mainKind.nonDeductibleKindCode != "" && typeof (pack[mainKind.nonDeductibleKindCode]) != "undefined") {
                    this.seleValue[mainKind.kindCode].nonSele = true;
                } else {
                    this.seleValue[mainKind.kindCode].nonSele = false;
                }

            }
        },
        setText(val) {
            if (val) {
                this.text = "保费计算";
            } else {
                this.text = "正在保费计算...";
            }
        },
        goOffer() {
            if (this.strongInsure) {
                this.seleValue['BZ'].mainSele = true;
            }
            if (!this.strongInsure && !this.commInsure) {
                return this.showErrorMsg("至少要选择商业险或交强险中的一种!");
            }
            if (this.baseIsQuery) {
                this.saveData();
                let query = {
                    _this: this,
                    seleValue: this.seleValue
                }
                this.$common.storeCommit(this, Car_Mutations.CAR_OFFER, query);
            }

        },
        addChange(val) {
            //判断是否需要投保其他险种才可以选择
            let mainKindCode = this.car.relationSave[val].mainKindCode;
            if (mainKindCode != null && mainKindCode != "" && !this.seleValue[mainKindCode].mainSele) {
                let msg = "需要选择 " + this.car.saveKind[mainKindCode].kindCName + " 才可以选择此险";
                this.showErrorMsg(msg, false);
                this.seleValue[val].mainSele = false;
                this.seleValue[val].nonSele = false;
            }
            if (this.seleValue[val].mainSele) {
                this.seleValue[val].nonSele = true;
            } else {
                this.seleValue[val].nonSele = false;
            }
            if (this.seleValue[val].excludeCode != "" && this.seleValue[val].excludeCode != null && this.seleValue[val].mainSele) {
                this.seleValue[this.seleValue[val].excludeCode].mainSele = false;
                this.seleValue[this.seleValue[val].excludeCode].nonSele = false;
            }
        },
        kindCodeMain(kindCode) {
            let mainSele = this.seleValue[kindCode].mainSele;
            if (!mainSele) {
                if (typeof (this.car.addMain[kindCode]) != "undefined") {
                    let mainList = this.car.addMain[kindCode];
                    for (let index in mainList) {
                        if (typeof (this.seleValue[index]) != "undefined") {
                            this.seleValue[index].mainSele = false;
                            this.seleValue[index].nonSele = false;
                        }
                    }
                }
            }
        },
        mainChange(val) {
            // debugger
            // let test = this.seleValue[val].mainSele;
            // console.log(test);
            this.saveData();
            let kindCode = this.seleValue[val].mainKindCode;
            this.kindCodeMain(val);
            //判断是否需要投保其他险种才可以选择
            if (typeof (this.car.addMain[val]) != "undefined" && !this.seleValue[val].mainSele) {
                //查询到其他附加险种必须投保该主险 
                let addKind = this.car.addMain[val];
                for (let i = 0; i < addKind.length; i++) {
                    this.seleValue[addKind[i]].mainSele = false;
                    this.seleValue[addKind[i]].nonSele = false;
                }
                this.seleValue[val].nonSele = false;
            } else {
                if (this.seleValue[val].mainSele) {
                    this.seleValue[val].nonSele = true;
                } else {
                    this.seleValue[val].nonSele = false;
                }
            }
            if (this.seleValue[val].excludeCode != "" && this.seleValue[val].mainSele) {
                this.seleValue[this.seleValue[val].excludeCode].mainSele = false;
                this.seleValue[this.seleValue[val].excludeCode].nonSele = false;
                this.kindCodeMain(this.seleValue[val].excludeCode);
            }
        },
        showErrorMsg(errorMsg, type) {
            this.$vux.alert.show({ content: this.$common.alertMsg(errorMsg, "red;") });
            if (type) {
                return false;
            } else {
                setTimeout(() => {
                    this.$vux.alert.hide();
                }, 5000);
                return false;
            }
        },
        goBack() {
            this.$common.goBackUrl(this, RouteUrl.ADD_CAR_INFO);
        },
        //保存
        saveData() {
            let query = {
                seleValue: this.seleValue,
                tprpTmainDto: this.tprpTmainDto,
                strongInsure: this.strongInsure,
                commInsure: this.commInsure,
                packIndex: this.packIndex,
                seleAxtx: this.seleAxtx,
                seleAtqqb: this.seleAtqqb,
                axtxInsure: this.axtxInsure,
                atqqbInsure: this.atqqbInsure,
                renewalDataChange: this.renewalDataChange,
                seleCrossValue: this.seleCrossValue
            }

            console.log('--------------------------');
            this.$common.storeCommit(this, Car_Mutations.CAR_OFFER_SAVE, query);
        },
        setData() {
            // debugger
            let _this = this;
            if (typeof (this.car.userSeleList[this.car.licenseNo]) == "undefined") {
                this.seleValue = this.car.baseUserSeleList;
                //如果以前有过续保操作 则把用户以前选择的保险进行赋值
                //循环当前配置的主险  查看是否在当中
                let renewalKindCode = this.car.curInfo.renewalKindCode;
                let mainRiskList = this.car.mainRiskSave;
                this.setDefaultSele(renewalKindCode, mainRiskList);
                let addRiskList = this.car.additionalInsurance;
                this.setDefaultSele(renewalKindCode, addRiskList);
            } else {
                this.seleValue = this.car.userSeleList[this.car.licenseNo];
            }
            if (typeof (this.car.baseCarOffer[this.car.licenseNo]) == "undefined") {
                this.strongInsure = true;
                this.commInsure = true;
                this.packIndex = 0;
            } else {
                let baseCarOffer = this.car.baseCarOffer[this.car.licenseNo];
                this.strongInsure = baseCarOffer.strongInsure;
                this.commInsure = baseCarOffer.commInsure;
                this.packIndex = baseCarOffer.packIndex;
            }
            let carInfoList = _this.car.carInfoList[_this.car.licenseNo];

            this.seleAxtx = carInfoList.sele2724;
            this.seleAtqqb = carInfoList.sele3105;
            this.axtxInsure = carInfoList.axtxInsure;
            this.atqqbInsure = carInfoList.atqqbInsure;
            this.renewalDataChange = carInfoList.renewalDataChange;

            //续保查询 对应日期要接上
            if (carInfoList.renewalFlag == "1" && carInfoList.renewalDataChange.renewalFlag == "0") {
                this.renewalDataChange.renewalFlag = "1";
                let insureCurDate = DateUtil.getDateTomorrow(1);
                let mainDto = carInfoList.tprpTmainDto;
                let mainQuery = carInfoList.tprpTmainDtoQuery;
                if (mainDto.combineFlag == "COMBINE") {
                    this.strongInsure = true;
                    this.commInsure = true;
                } else if (mainDto.combineFlag == "MOTOR") {
                    this.commInsure = true;
                } else if (mainDto.combineFlag == "MTPL") {
                    this.strongInsure = true;
                }

                if (mainDto.endDate != "" && mainDto.endDate != null && mainDto.endDate >= insureCurDate) {
                    carInfoList.tprpTmainDtoQuery.startDate = mainDto.endDate;
                    if (mainDto.endHour == "24" || mainDto.endHour == 24) {
                        this.renewalDataChange.renewalStartDate = DateUtil.getDateAfterOfDay(mainDto.endDate.replace("-", "/").replace("-", "/").replace("-", "/"), 1);
                        carInfoList.tprpTmainDtoQuery.startDate = this.renewalDataChange.renewalStartDate;
                    }
                    // if(mainDto.startHour!=""&&mainDto.startHour!=null){
                    //     carInfoList.tprpTmainDtoQuery.startHour =mainDto.startHour;
                    // }
                }
                if (mainDto.mtplEndDate != "" && mainDto.mtplEndDate != null && mainDto.mtplEndDate >= insureCurDate) {
                    carInfoList.tprpTmainDtoQuery.mtplStartDate = mainDto.mtplEndDate;

                    if (mainDto.mtplEndHour == "24" || mainDto.endHour == 24) {
                        this.renewalDataChange.renewalMtplStartDate = DateUtil.getDateAfterOfDay(mainDto.mtplEndDate.replace("-", "/").replace("-", "/").replace("-", "/"), 1);
                        carInfoList.tprpTmainDtoQuery.mtplStartDate = this.renewalDataChange.renewalMtplStartDate;
                    }

                    // if(mainDto.startHour!=""&&mainDto.startHour!=null){
                    //     carInfoList.tprpTmainDtoQuery.startHour =mainDto.startHour;
                    // }
                }


            }
            console.log('-------------------------');
            console.log(carInfoList);
            console.log(carInfoList.tprpTmainDtoQuery);
            setTimeout(() => {
                _this.tprpTmainDto = _this.$common.getNewObject(carInfoList.tprpTmainDtoQuery);
                console.log(carInfoList.tprpTmainDtoQuery);
                _this.seleCrossList = carInfoList.seleCross;
                _this.seleCrossValue = carInfoList.seleCrossValue;
                // debugger
                if (typeof (carInfoList.seleCrossValue) != "undefined") {
                    _this.seleCrossValue = carInfoList.seleCrossValue;
                }
            }, 500);
        },
        setDefaultSele(renewalKindCode, riskList) {
            if (this.car.curInfo.isSetrenewalKindCode) {
                // debugger
                for (let i = 0; i < riskList.length; i++) {
                    let main = riskList[i];
                    let kindCode = main.kindCode;   //主险种
                    let nonDeductibleKindCode = main.nonDeductibleKindCode;        //不计免赔
                    //查看主险是否在其中
                    if (typeof (renewalKindCode[kindCode]) == "undefined") {
                        this.seleValue[kindCode].mainSele = false;
                    } else {
                        this.seleValue[kindCode].mainSele = true;
                        let val = renewalKindCode[kindCode].amountMain;
                        if (val != "" && val != null && val != "0" && val != "0.0") {
                            // console.log(renewalKindCode[kindCode].amountMain);
                            this.seleValue[kindCode].defValue = renewalKindCode[kindCode].amountMain + "0";
                            // console.log(this.seleValue[kindCode].defValue);
                        }
                    }

                    //查看是否选择了不计免赔
                    if (typeof (renewalKindCode[nonDeductibleKindCode]) == "undefined") {
                        this.seleValue[kindCode].nonSele = false;
                    } else {
                        this.seleValue[kindCode].nonSele = true;
                    }
                }
            }
        }
    },
    beforeRouteEnter(to, from, next) {
        sessionStorage["CAR_FORM_URL"] = from.path;
        next();
    },
    beforeMount() {
        if (sessionStorage["CAR_FORM_URL"] != "/") {
            this.setData();
        }
    },
    beforeDestroy() {
        if (sessionStorage["CAR_FORM_URL"] != "/") {
            this.saveData();
        }
    },
    mounted() {
        document.title = '报价';
        if (sessionStorage["CAR_FORM_URL"] == "/") {
            this.$common.goUrl(this, RouteUrl.CAR_INSURE);
            return;
        }
        // if (!this.car.isQueryCar) {
        // this.setQueryInfo();
        // this.fuelTypeList = CarConfig.getFuelType();
        this.$init.subPageInit(this);
        this.setText(this.baseIsQuery);
        // let initQuery = {
        //     _this: this,
        //     riskCode: "0502"
        // }
        // this.$common.storeCommit(this, Car_Mutations.CAR_OFFER_INIT, initQuery);

        // }
        //初始化，没有footer
        // this.carKindList = CarConfig.getCarKind();
        // window.addEventListener('load', function() {
        //     _this.saveData();
        // });
        // window.addEventListener('popstate', function(ev) {
        //     _this.saveData();
        // });
        // this.hourseType = Config.getHouseType();
        //添加上一个页面的价钱

    }
};
</script>

<style  lang="scss">
.insure__iconspan {
  position: absolute;
  margin-top: 4px;
  width: 4px;
  height: 18px;
  background-color: #c8161d;
}
.caroffer-swich {
  padding-top: 5px !important;
  padding-bottom: 5px !important;
}
.insure__list--title {
  font-size: 15px;
  color: #c8161d;
}

.insure__iconspan--title {
  margin-left: 9px;
  font-size: 14px;
}

.car_offer {
  border: 1px solid #e7e7e7;
  margin: 0 5px;
}

.car_offer--group {
  .vux-no-group-title {
    padding-bottom: 20px;
  }
}

.insure__footer {
  position: fixed;
  bottom: 0px;
  z-index: 5;
  width: 100%;
  height: 47px;
  background-color: white;
  div {
    height: 100%;
    line-height: 47px;
    text-align: center;
    font-size: 20px;
  }
  box-shadow: 0px 0px 10px 1px #efefef;
}
.car-input {
  .weui-cell__bd {
    input {
      text-transform: uppercase;
    }
  }
}
.min-offer_input {
  border-radius: 3px;
  border: 1px solid #e5e5e5;
}
.insure__rightbtn {
  background: #c8161d;
  color: #fff;
}

.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s;
}

.fade-enter,
.fade-leave-to {
  transition: opacity 0.1s;
}

.insure__input-datatime {
  height: 24px;
  line-height: 0px;
  font-size: 14px;
  //   color: #7f7f7f !important;
  .weui-cell__ft {
    text-align: justify;
    color: #999999;
  }
}

.insure__input {
  //   line-height: 0px;
  font-size: 14px;
  //   color: #7f7f7f !important;
  .weui-cell__ft {
    text-align: justify;
    color: #999999;
  }
}

.base-car-selector {
  .weui-cell:before {
    border-top: 0px !important;
  }
}
.carinfo-selector {
  .weui-label {
    line-height: 0px;
    font-size: 14px;
  }
  select {
    direction: rtl;
  }
}
input::-webkit-input-placeholder {
  font-size: 14px;
  color: #7f7f7f;
}
.caroffrt-input {
  color: #000;
}
.carinfo-input {
  input {
    text-align: right;
  }
}
.offer-min-input {
  display: block;
  float: left;
  line-height: 32px;
  width: 100px;
}
.accident {
  margin-right: 15px !important;
  width: 120px !important;
}
.sele-caroffer {
  border: 1px solid #d7d7d7;
  margin-right: -10px;
  display: block;
  float: left;
  //   line-height: 32px;
  width: 85px;
  border-radius: 3px;
  //   border: 1px solid #e5e5e5;
  height: 32px;
  select {
    text-align-last: center;
    padding-right: 10px !important;
    padding-left: 0px !important;
    height: 32px;
    line-height: 32px;
  }
  .weui-cell__bd:after {
    right: 8px !important;
  }
}

.dataTime-select {
  border: 1px solid #fff;
  .insure__input {
    color: #fff !important;
    line-height: 15px !important;
    font-size: 13px;
  }
  .vux-cell-value {
    color: #fff !important;
    font-size: 13px !important;
  }
  .weui-cell__ft:after {
    border-width: 0px 2px 2px 0 !important;
    border-color: #FFFF !important;
  }
  .vux-datetime {
    display: flex !important;
    padding: 0px 0px !important;
  }
}
.carrisk-name {
  font-size: 14px;
}
.caroffer-insure {
  .weui-icon-success {
    font-size: 18px !important;
  }
  .weui-icon-success-circle {
    font-size: 18px !important;
  }
  .weui-icon-circle {
    font-size: 18px !important;
  }
}
.title-selector {
  height: 28px;
  label {
    color: #000;
  }
}
.SendEmail__list--title {
  float: left;
  font-size: 15px;
  color: #c8161d;
  border-top: 1px solid #fff;
}

.SendEmail__iconspan {
  position: absolute;
  margin-top: 3px;
  width: 4px;
  height: 18px;
  background-color: #c8161d;
}

.SendEmail__iconspan--title {
  margin-left: 9px;
  font-size: 16px;
}

.SendEmail__Einv--title {
  padding-top: 0px !important;
  border-top: 1px solid #fff;
  margin-left: -8px;
}

.SendEmail__formPolicy {
  border: 1px solid #e7e7e7;
  //   margin: 0 5px;
  .weui-cell {
    padding: 5px 7px !important;
  }
}

.SendEmail__formPolicy--group {
  padding: 0px 10px; // .vux-no-group-title {
  //     padding-bottom: 20px;
  // }
}

.dialog__Einv--div {
  margin-top: -7px;
}

.dialog__Einv--btn {
  float: right;
  margin-right: 13px;
}
.dialog-btnlist {
  margin-top: -5px;
  margin-bottom: 5px;
}
</style>
